package com.rf.richfitwheel.dyn.business.constants;


public class DataBaseColumnType {
    public static final String[] MYSQL = {"TINYINT",
            "SMALLINT",
            "MEDIUMINT",
            "INT",
            "BIGINT",
            "FLOAT",
            "DOUBLE",
            "DECIMAL",
            "CHAR",
            "VARCHAR",
            "TEXT",
            "YEAR",
            "TIME",
            "DATE",
            "DATETIME",
            "TIMESTAMP"};
    public static final String[] PostgreSQL = {"smallint",
            "integer",
            "bigint",
            "decimal",
            "numeric",
            "real",
            "double",
            "smallserial",
            "serial",
            "bigserial",
            "char",
            "varchar",
            "text",
            "date",
            "time",
            "timestamp"};
    public static final String[] ORACLE = {"CHAR", "VARCHAR2", "DATE", "NUMBER", "DECIMAL", "INTEGER", "FLOAT", "REAL"};

    //匹配方式
    public static final String QUERY_TYPE_EQ = "eq";
    public static final String QUERY_TYPE_LIKE = "like";
    public static final String QUERY_TYPE_NE = "ne";
    public static final String QUERY_TYPE_IN = "in";
    public static final String QUERY_TYPE_LE = "le";
    public static final String QUERY_TYPE_GE = "ge";
    public static final String QUERY_TYPE_GT = "gt";
    public static final String QUERY_TYPE_LT = "lt";
    public static final String QUERY_TYPE_ISNULL = "isnull";
    public static final String QUERY_TYPE_NOTNULL = "notnull";
    public static final String QUERY_TYPE_NOT_IN = "notIn";
    public static final String QUERY_TYPE_BETWEEN = "between";
    public static final String QUERY_TYPE_LEFT_LIKE = "leftLike";
    public static final String QUERY_TYPE_RIGHT_LIKE = "rightLike";

    public enum MysqlCommonColumnType {
        VARCHAR("VARCHAR2"),
        DATETIME("DATETIME");
        private final String value;
        MysqlCommonColumnType(String value) {
            this.value = value;
        }
        public String getValue() {
            return value;
        }
    }

    public enum PostgreSQLCommonColumnType {
        VARCHAR("varchar"),
        DATETIME("timestamp");
        private final String value;
        PostgreSQLCommonColumnType(String value) {
            this.value = value;
        }
        public String getValue() {
            return value;
        }
    }

    public enum OracleCommonColumnType {
        VARCHAR("VARCHAR2"),
        DATETIME("DATE");
        private final String value;
        OracleCommonColumnType(String value) {
            this.value = value;
        }
        public String getValue() {
            return value;
        }
    }

    /**
     * 根据数据库类型获取数据字段类型的名称
     * @param dialect 数据库类型
     * @param colType 字段类型
     * @return 名称
     */
    public static String getDataBaseCommonColumnType(String dialect, String colType){
        switch (dialect) {
            case "mysql" : {
                return MysqlCommonColumnType.valueOf(colType).getValue();
            }
            case "postgresql" : {
                return PostgreSQLCommonColumnType.valueOf(colType).getValue();
            }
            case "oracle" : {
                return OracleCommonColumnType.valueOf(colType).getValue();
            }
            default : {
                return "";
            }
        }
    }
}
